*==============================================================================*
*           effects of tier 0 exhaust standards on vehicle emissions           *
*==============================================================================*




*------------------- panels a-b: 1957-1971 FTP ---------------------------*
u "replicationFiles/dataSTATA/combined/combined_aes73.dta", clear


keep emissions_new_CO_noncalifornia emissions_new_HC_noncalifornia emissions_new_NOX_noncalifornia emissions_new_CO2_noncalifornia ///
	emissions_new_CO_california emissions_new_HC_california emissions_new_NOX_california emissions_new_CO2_california ///
	n_california n_noncalifornia model_year standardfederal*

foreach p in CO CO2 HC NOX {
	ren emissions_new_`p'_noncalifornia emissionsfederal`p'
	ren emissions_new_`p'_california    emissionscalifornia`p'
	g emissionsNfederal`p' = n_noncalifornia
	g emissionsNcalifornia`p' = n_california
}
	
* pre-regulation standards set equal to uncontrolled mean (from NRC for
* criteria pollutants and about equal to data mean here)
replace standardfederalCO  = 90  if model_year <= 1967 & standardfederalCO  >= .
replace standardfederalHC  = 8.2 if model_year <= 1967 & standardfederalHC  >= .
replace standardfederalNOX = 3.4 if standardfederalNOX >= .

g       standardcaliforniaCO  = 90  if model_year <= 1965 
g       standardcaliforniaHC  = 8.7 if model_year <= 1965 
replace standardcaliforniaCO  = 44  if model_year >= 1966 & model_year <= 1969
replace standardcaliforniaHC  = 4.3 if model_year >= 1966 & model_year <= 1969
replace standardcaliforniaCO  = 23  if model_year >= 1970 & model_year <= 1971
replace standardcaliforniaHC  = 2.2 if model_year >= 1970 & model_year <= 1971
g       standardcaliforniaNOX = 3.4 
g       standardcaliforniaCO2 = 496 


reshape long standardfederal standardcalifornia emissionsfederal ///
	emissionscalifornia emissionsNfederal emissionsNcalifornia, ///
	i(model_year) j(pollutant) string

reshape long standard emissions emissionsN, i(model_year pollutant) j(region) string

g lnstandard  = ln(standard)
g lnemissions = ln(emissions)

egen regionXpollutant     = group(region pollutant)



xi: reghdfe lnemissions lnstandard                          , vce(robust) absorb(regionXpollutant)
	est store m1_all
xi: reghdfe lnemissions lnstandard                          , vce(robust) absorb(regionXpollutant model_year)
	est store m2_all
xi: reghdfe emissions   standard                            , vce(robust) absorb(regionXpollutant model_year)
	est store m3_all
xi: reghdfe lnemissions lnstandard if region == "california", vce(robust) absorb(regionXpollutant)
	est store m4_all
xi: reghdfe lnemissions lnstandard if region == "california", vce(robust) absorb(regionXpollutant model_year)
	est store m5_all
xi: reghdfe lnemissions lnstandard if region == "federal"   , vce(robust) absorb(regionXpollutant)
	est store m6_all
xi: reghdfe lnemissions lnstandard if region == "federal"   , vce(robust) absorb(regionXpollutant model_year)
	est store m7_all

	
foreach p in CO HC {
	xi: reghdfe lnemissions lnstandard if pollutant == "`p'", vce(robust) absorb(region pollutant)
		est store m1_`p'
	xi: reghdfe lnemissions lnstandard if pollutant == "`p'", vce(robust) absorb(model_year region pollutant)
		est store m2_`p'
	xi: reghdfe   emissions   standard if pollutant == "`p'", vce(robust) absorb(model_year region pollutant)
		est store m3_`p'
	xi: reghdfe lnemissions lnstandard if pollutant == "`p'" & region == "california", vce(robust) absorb(region pollutant)
		est store m4_`p'
	xi: reghdfe lnemissions lnstandard if pollutant == "`p'" & region == "california", vce(robust) absorb(region pollutant)
		est store m5_`p'
}



estout m* ///
using "results/tables/t2_tier0.txt", ///
	cells( b(star fmt(%9.2f)) se(par(`"="("'`")""'))) ///
	title("Effects of Tailpipe Standards on Emissions, 1957-1971") style(tab) keep(*standard*) ///
	stats(N N_clust, fmt(0 0 3) labels(N "Clusters")) label collabels(, none) ///
	starlevels(* .10 ** .05 *** .01) replace

	
	
	